<?php							
		class CType extends database
		{
			var $table = 'cdb_type';
			
			public function CTypeSearchResult($keyWord)
			{
				$sql="select * from $this->table where name like '{$keyWord}'";
				$this->setQuery($sql);
				$this->query();
				$arr = $this->loadAllRow();
				
				$numOfRow = mysql_affected_rows();
				
				if($numOfRow>0)
					return $arr;
				else
					return -1;				
			}
			
			
			public function CTypeListOfCategory($id_category)
			{
				$sql="select * from $this->table where id_category='{$id_category}'";
				$this->setQuery($sql);
				$this->query();
				$arr = $this->loadAllRow();
				
				$numOfRow = mysql_affected_rows();
				
				if($numOfRow>0)
					return $arr;
				else
					return -1;	
			}
			
			public function CTypeList ()
			{
				$sql = "select * from {$this->table} "	;
				$this->setQuery($sql);
				$this->query();
				$arrTemp =  $this->loadAllRow();				
				
				$numOfRow = mysql_affected_rows();
				if($numOfRow>0)
					return $arrTemp; 
				else
					return -1;
			}
			
			public function CTypeDetail ($id)
			{
				$sql="select * from $this->table where id='{$id}'";
				$this->setQuery($sql);
				$this->query();
				$arr=$this->loadAllRow();
				$numOfRow = mysql_affected_rows();
				if($numOfRow>0)
					return $arr[0];
				else
					return -1;
			}
			
			
			
			public function CTypeAdd ($id_category,$name,$description,$status)
			{
				$sql = "INSERT INTO {$this->table} (`id_category`,`name`,`description`,`status`)
	VALUES ('{$id_category}','{$name}','{$description}','{$status}');";
				
				$this->setQuery($sql);
				$this->query();	
				return mysql_affected_rows();
				
			}
			
			public function CTypeUpdate ($id,$id_category,$name,$description,$status)
			{
				$sql = "update $this->table set id ='{$id}',id_category ='{$id_category}',name ='{$name}',description ='{$description}',status ='{$status}' where id = '{$id}' ";
			
				$this->setQuery($sql);
				$this->query();
				return mysql_affected_rows();
			}
			
			public function CTypeDelete($id)
			{
				$sql="Delete from  $this->table where id='{$id}'";
				$this->setQuery($sql);
				$this->query();
				return mysql_affected_rows();
			}
			
		}
	
	
	
	?>